import Vue from 'vue';
import Router from 'vue-router'
import Layout from '../layouts/Layout'

Vue.use(Router);
const originalPush = Router.prototype.push

Router.prototype.push = function push (location) {
    return originalPush.call(this, location).catch(err => err)
}
export const constantRouterMap =
    [
        {
            path:'/',
            redirect:'/login',
            hidden:true,
        },{
            path:'/login',
            name: 'login',
            hidden:true,
            component : ()=> import('../views/login/index'),
        },
        {
            path:'/setting/account',
            name:'setting/account',
            meta:{
                title:'个人设置',
                icon:'el-icon-s-tools',
                roles:'USER_MANAGEMENT'
            },
            redirect:'/setting/dictionary',
            component:Layout,
            children:[
                 {
                    path:'/setting/account',
                    name:'account',
                    meta:{
                        hidden:false,
                        title:'账户设置'
                    },
                    component : ()=> import('../views/setting/account'),
                },
            ]
        },
        // {
        //     path: '',
        //     component: Layout,
        //     redirect: '/dashboard',
        //     meta: {
        //         title: '首页',
        //         icon:'el-icon-s-grid',
        //      },
        //     children: [
        //       {
        //         path: '/dashboard',
        //         component: () => import('../views/dashboard/index'),
        //         name: 'Dashboard',
        //         meta: {
        //            title: '首页121',
        //            icon:'el-icon-s-grid',
        //         }
        //       }
        //     ]
        //   }
        //   ,
          {
              path:'/pusher/detail',
              component:Layout,
              hidden:true,
              redirect:'/pusher/details',
              children:[{
                  path:'/pusher/details',
                  component:()=>import('../views/pusher/task/details'),
                  meta:{
                      hidden:true,

                  }
              }]
          }
    ]

export const asyncRouterMap = [
    {
        path:'/facility',
        name:'facility',
        redirect:'/facility/info',
        component:Layout,
        meta:{
            title:'设备管理',

            icon:'el-icon-s-grid',
            roles:'DEVICE_MANAGEMENT'
        },
        children:[
            {
                path:'/facility/info',
                name:'facilityInfo',
                meta:{

                    title:'设备信息'
                },
                component : ()=> import('../views/facility/info'),
            },
            {
                path:'/facility/directiveGroup',
                name:'directiveGroup',
                meta:{
                    title:'指令簇'
                },
                component : ()=> import('../views/facility/directiveGroup'),
            },
            {
                path:'/facility/directive',
                name:'directive',
                meta:{
                    title:'指令'
                },
                component : ()=> import('../views/facility/directive'),
            },{
                path:'/facility/script',
                name:'script',
                meta:{
                    title:'脚本'
                },
                component : ()=> import('../views/facility/script'),
            }
        ]
    },
    {
        path:'/collector',
        name:'collector',
        redirect:'/collector/info',
        component:Layout,
        meta:{
            title:'采集器',
            icon:'el-icon-s-cooperation',
            roles:'COLLECTOR_MANAGEMENT'
        },
        children:[
            {
                path:'/collector/info',
                name:'collectorInfo',
                meta:{
                    hidden:false,
                    title:'信息'
                },
                component : ()=> import('../views/collector/info'),
            },
            {
                path:'/collector/content',
                name:'content',
                meta:{
                    hidden:false,
                    title:'内容分类'
                },
                component : ()=> import('../views/collector/content'),
            }, {
                path:'/collector/task',
                name:'collectorTask',
                meta:{
                    hidden:false,
                    title:'任务'
                },
                component : ()=> import('../views/collector/task'),
            },
        ]
    },
    {
        path:'/pusher',
        name:'pusher',
        redirect:'/pusher/info',
        component:Layout,
        meta:{
            title:'推送器',
            icon:'el-icon-s-promotion',
            roles:'PUSHER_MANAGEMENT'
        },
        children:[
            {
                path:'/pusher/info',
                name:'pusherInfo',
                meta:{
                    hidden:false,
                    title:'信息'
                },
                component : ()=> import('../views/pusher/info'),
            },
            {
                path:'/pusher/target',
                name:'target',
                meta:{
                    hidden:false,
                    title:'推送目标'
                },
                component : ()=> import('../views/pusher/target'),
            }, {
                path:'/pusher/task',
                name:'pusherTask',
                meta:{
                    hidden:false,
                    title:'任务'
                },
                component : ()=> import('../views/pusher/task'),
            },
        ]
    },{
        path:'/setting',
        name:'setting',
        meta:{
            title:'设置',
            icon:'el-icon-s-tools',
            roles:'USER_MANAGEMENT'
        },
        redirect:'/setting/dictionary',
        component:Layout,
        children:[
            {
                path:'/setting/dictionary',
                name:'dictionary',
                meta:{
                    hidden:false,
                    title:'权限字典'
                },
                component : ()=> import('../views/setting/dictionary'),
            },
            {
                path:'/setting/role',
                name:'role',
                meta:{
                    hidden:false,
                    title:'角色设置'
                },
                component : ()=> import('../views/setting/role'),
            },{
                path:'/setting/system',
                name:'system',
                meta:{
                    hidden:false,
                    title:'系统设置'
                },
                component : ()=> import('../views/setting/system'),
            },
        ]
    },
   

]
export default new Router({
    scrollBehavior: () => ({ y: 0 }),
    mode:'hash',
    routes:constantRouterMap
})

